<?php

/**  **/
// 产品 id  回话id 目前改为用户id
// $shang_pin_id = $_POST['key0'];
// 用户名 相当于token串
//// $yong_hu_ming = $_POST['key1'];
// 用户发送内容
//// $xiao_xi_nei_rong = $_POST['key2'];
// 发送方向， 有客户向客服发送的消息，设定为1
$fa_song_fang_xiang = "1";
// 发送之后，插入数据库

$yong_hu_ming = "1234";
$xiao_xi_nei_rong = "xxxx"; 

// 开DB连接
//  $dbConnection = new PDO('mysql:dbname=firstpanda;host=127.0.0.1;charset=utf8', 'firstpanda', 'Apanda13689');
$dbConnection = new PDO('mysql:dbname=dhshop;host=127.0.0.1;charset=utf8', 'root', 'panda123');
$dbConnection->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);
$dbConnection->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
// 将用户发送的消息插入数据库
//$stmt = $dbConnection->prepare('SELECT * FROM employees WHERE name = :name');
$stmt = $dbConnection->prepare('INSERT INTO xiao_xi_biao (hui_hua_id,yong_hu_id,xiao_xi_nei_rong,fa_song_shi_jian,fa_song_fang_xiang) VALUES (:hui_hua_id, :yong_hu_id, :xiao_xi_nei_rong, now(), :fa_song_fang_xiang)');
$stmt->execute(array(':hui_hua_id' => $yong_hu_ming,':yong_hu_id' => $yong_hu_ming,':xiao_xi_nei_rong' => $xiao_xi_nei_rong,':fa_song_fang_xiang' => $fa_song_fang_xiang));
// 关DB连接
$dbConnection = null;
// 重新检索 返回json

/**  检索回话记录，返回给用户 **/

// 从数据库中检索 与客户相关的消息， 按时间倒叙排列，检索最近50条。
// 开DB连接
//  $dbConnection = new PDO('mysql:dbname=firstpanda;host=127.0.0.1;charset=utf8', 'firstpanda', 'Apanda13689');
$dbConnection = new PDO('mysql:dbname=dhshop;host=127.0.0.1;charset=utf8', 'root', 'panda123');
$dbConnection->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);
$dbConnection->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);

$stmt = $dbConnection->prepare('SELECT hui_hua_id, xiao_xi_nei_rong, fa_song_shi_jian FROM xiao_xi_biao WHERE hui_hua_id = :hui_hua_id ORDER BY fa_song_shi_jian DESC');
//$stmt = $dbConnection->prepare('INSERT INTO fang_wen_ji_lu_biao (cookie_ban_ben,yong_hu_zhang_hao,yong_hu_mi_ma,fang_wen_url,fang_wen_shi_jian,ip,she_bei,liu_lan_qi) VALUES (:cookie_ban_ben,:yong_hu_zhang_hao,:yong_hu_mi_ma,:fang_wen_url,now(),:ip,:she_bei,:liu_lan_qi)');
$stmt->execute(array(':hui_hua_id' => $yong_hu_ming));
/*
while ($row = $stmt->fetchAll()) {
//  $resultContent = $resultContent . ""
//	print_r($row[0][hui_hua_id]);
//  $count++;

print_r($row);
echo
}
*/
while($row)

echo json_encode($stmt->fetchAll());


// 关DB连接 
$dbConnection = null;

//echo json_encode($stmt->fetchAll());

//echo "{\"count\":\"2\", \"result\":[{\"a\":\"a\",\"1\":\"b\",\"2\":\"c\",\"3\":\"d\"},{\"a\":\"a2\",\"1\":\"b\",\"2\":\"c\",\"3\":\"d\"}]}";

 ?>
